﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace DataAccess
{
    public class LoaiDiem
    {
        public int MaD { get; set; }
        public string TenDiem { get; set; }

        public LoaiDiem() { }

        public static LoaiDiem TimLoaiDiemTheoMa(int ma)
        {
            //return CBO.FillObject<LoaiDiem>(DataProvider.Instance.ExecuteReader("LoaiDiem_TimTheoMa",ma));
            using (SqlConnection cnn = MyConnection.MyConn())
            {
                SqlCommand cmd = cnn.CreateCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "LoaiDiem_TimTheoMa";
                cmd.Parameters.Add("@MaD", SqlDbType.Int).Value = ma;
                cnn.Open();
                using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    if (reader.Read())
                    {
                        LoaiDiem data = GetData(reader);
                        return data;
                    }
                    else return null;
                }
            }
        }

        private static LoaiDiem GetData(SqlDataReader read)
        {
            LoaiDiem data = new LoaiDiem();
            data.MaD = CType.ToInt32(read["MaD"]);
            data.TenDiem = CType.Tostring(read["TenDiem"]);
            return data;
        }
    }
}
